<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./permission.xhtml">

            <ui:define name="tabContent">
                <h:form>
                    <p:panel>

                        <h:panelGrid columns="2">
                            Tên chức năng*     <p:inputText value="#{resourceBean.selected.name}"
                                                            required="true" requiredMessage="Bạn chưa nhập tên chức năng"/>
                            Mô tả    
                            <p:inputTextarea value="#{resourceBean.selected.description}" />
                        </h:panelGrid>


                        <h:panelGrid columns="5">
                            <p:commandButton ajax="false" value="Thêm mới" rendered="#{!resourceBean.edit}" action="#{resourceBean.create()}"/>
                            <p:commandButton ajax="false" value="Cập nhật" rendered="#{resourceBean.edit}" action="#{resourceBean.edit()}"/>
                            <p:commandButton ajax="false" value="Hủy bỏ" immediate="true" action="#{resourceBean.resetToCreateForm()}"/>
                        </h:panelGrid>
                    </p:panel>
                </h:form>
                <br/>
                <h:form>

                    <p:dataTable id="table" value="#{resourceBean.list}" var="item" paginator="#{resourceBean.list.size() >20}" rows="20" 
                                 selection="#{resourceBean.selectedList}" selectionMode="multiple" resizableColumns="true"
                                 rowKey="#{item.id}">

                        <f:facet name="header">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{resourceBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="resourceDeleteConfirm.show()" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <f:facet name="footer">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{resourceBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="resourceDeleteConfirm.show()" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <p:column headerText="Tên chức năng" sortBy="#{item.name}">
                            #{item.name}
                        </p:column>
                        <p:column headerText="Mô tả" sortBy="#{item.description}">
                            #{item.description}
                        </p:column>
                    </p:dataTable>

                    <p:confirmDialog message="Bạn muốn xóa các bản ghi đã chọn?"  
                                     header="Xác nhận" severity="alert" widgetVar="resourceDeleteConfirm">  

                        <p:commandButton update="table" value="Có" oncomplete="resourceDeleteConfirm.hide()"  
                                         action="#{resourceBean.remove()}"/>
                        <p:commandButton value="Không" onclick="resourceDeleteConfirm.hide()" type="button" />   

                    </p:confirmDialog> 

                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
